package com.iot.comprehensive.face.service.impl;

import com.iot.comprehensive.face.dao.AccountDao;
import com.iot.comprehensive.face.dao.AdminDao;
import com.iot.comprehensive.face.dao.UserDao;
import com.iot.comprehensive.face.model.Admin;
import com.iot.comprehensive.face.service.AdminService;
import org.springframework.stereotype.Service;

/**
 * @Author 朱泽玉
 * @Create 2021/6/27 16:09
 * @Description
 * @Modified By:
 */
@Service
public class AdminServiceImpl implements AdminService {
    final AdminDao adminDao;
    final UserDao userDao;
    final AccountDao accountDao;

    public AdminServiceImpl(AdminDao adminDao, UserDao userDao, AccountDao accountDao) {
        this.adminDao = adminDao;
        this.userDao = userDao;
        this.accountDao = accountDao;
    }

    @Override
    public void add(Admin admin) {
        adminDao.save(admin);
    }

    @Override
    public void update(Admin admin) {
        Admin admin_data = adminDao.findById(admin.getId()).orElse(null);
        admin_data.setName(admin.getName());
        admin_data.setDescription(admin.getDescription());
        adminDao.save(admin_data);
    }

    @Override
    public Admin findByAccountId(Long account_id) {
        return adminDao.findById(account_id).orElse(null);
    }

    @Override
    public Admin findById(Long id) {
        return adminDao.findById(id).orElse(null);
    }

    @Override
    public void del(Long id) {
        adminDao.deleteById(id);
    }
}
